<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/13
 * Time: 14:52
 */
include "../classes/logincheck.php";
include '../classes/conn.php';
if(islogin()!='teacher_login'){
    die('error');
}

$sec_num_old=$_POST['sec_num_old'];
$sec_num_new=$_POST['sec_num_new'];
$sec_name_new=$_POST['sec_name_new'];
$class_num=$_POST['class_num'];
if($sec_num_old==$sec_num_new) {

    $query1 = "update section set num='{$sec_num_new}',name='{$sec_name_new}' where num='{$sec_num_old}' and class='{$class_num}' and teacher='{$_SESSION['t_num']}'";
    mysql_query($query1);
}
else{
    $query2="select num from section where num='{$sec_num_new}' and class='{$class_num}' and teacher='{$_SESSION['t_num']}'";
    $res2=mysql_query($query2);
    if(mysql_num_rows($res2)){
        die('sec_num_exist');
    }

    $query1 = "update section set num='{$sec_num_new}',name='{$sec_name_new}' where num='{$sec_num_old}' and class='{$class_num}' and teacher='{$_SESSION['t_num']}'";
    mysql_query($query1);
    $query1="update subsection set section='{$sec_num_new}' where section='{$sec_num_old}' and class='{$class_num}' and teacher='{$_SESSION['t_num']}'";
    mysql_query($query1);

}